package com.hongkuncheng.cms;

import com.hongkuncheng.cms.helper.*;
import org.hibernate.FactorySession;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.Resource;

@EnableScheduling
@ServletComponentScan
@SpringBootApplication
public class Application implements ApplicationRunner {

    @Resource
    FactorySession factorySession;
    @Value(("${spring.application.directory}"))
    String applicationDirectory;
    @Value("${duanxin.apikey}")
    String duanxinApikey;
    @Value("${weibo.appKey}")
    String weiboAppKey;
    @Value("${weibo.appSecret}")
    String weiboAppSecret;
    @Value("${weixin.type}")
    String weixinType;
    @Value("${weixin.appId}")
    String weixinAppId;
    @Value("${weixin.appSecret}")
    String weixinAppSecret;
    @Value("${weixin.token}")
    String weixinToken;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ArticleHelper.factorySession = factorySession;
        TokenHelper.factorySession = factorySession;
        DuanxinHelper.apikey = duanxinApikey;
        WeiboHelper.factorySession = factorySession;
        WeiboHelper.initial(weiboAppKey, weiboAppSecret);
        WeixinHelper.factorySession = factorySession;
        WeixinHelper.initial(weixinType, weixinAppId, weixinAppSecret, weixinToken, applicationDirectory);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
